#include "StdAfx.h"
#include "DataConvert.h"


CDataConvert::CDataConvert(void)
{
}


CDataConvert::~CDataConvert(void)
{
}

//string CDataConvert::BSTRToString(BSTR Data)
//{
//	string ret;
//	_bstr_t b;
//	b = (_bstr_t)Data;
//	ret = b;
//	return ret;
//}
//
//boost::posix_time::ptime CDataConvert::OleTimeToPTime(COleDateTime tOle)
//{
//	SYSTEMTIME   systime; 
//	VariantTimeToSystemTime(tOle,   &systime); 
//
//	boost::posix_time::time_duration td(systime.wHour,systime.wMinute,systime.wSecond);
//	boost::gregorian::date tDate(systime.wYear,systime.wMonth,systime.wDay);
//	boost::posix_time::ptime ret(tDate,td);
//
//	PTimeToOleTime(ret);
//	return ret;
//
//}
//
//COleDateTime CDataConvert::PTimeToOleTime(boost::posix_time::ptime t)
//{
//	tm tmTime=boost::posix_time::to_tm(t);
//	time_t time2= mktime(&tmTime);
//	COleDateTime ret(time2); //time_t--->COleDateTime
//	//SYSTEMTIME   systime; 
//	//VariantTimeToSystemTime(ret,   &systime); 
//	//CTime   tm(systime); 
//	//string s;
//	//s=boost::lexical_cast<string>(t);
//
//	//SYSTEMTIME   systime; 
//	//VariantTimeToSystemTime(ret,   &systime); 
//	return ret;
//}
//
//string CDataConvert::PTimeToString(boost::posix_time::ptime t)
//{
//	string s;
//	s=boost::posix_time::to_iso_extended_string(t);
//	boost::replace_first(s,"T"," ");
//	return s;
//}
//
//string CDataConvert::UUIDToString(boost::uuids::uuid data)
//{
//	string s;
//	s=boost::lexical_cast<string>(data);
//	s="{"+s+"}";
//	return s;
//}
//
//boost::uuids::uuid CDataConvert::StringToUUID(string data)
//{
//	boost::uuids::uuid ret;
//	if (data.c_str()[0]!='{')
//	{
//		data="{"+data+"}";
//	}
//	boost::uuids::string_generator sgen;
//	ret =sgen(data.c_str());
//	return ret;
//}

UINT32 CDataConvert::Char4ToUInt32(unsigned char cLowLow,unsigned char cLowHigh,unsigned char cHighLow,unsigned char cHighHigh)
{
#ifdef IS_HIGH_BEFOR 
	return  (((cHighHigh<<8)+cHighLow)<<16)+((cLowHigh<<8)+cLowLow);
#else
	return  (((cLowLow<<8)+cLowHigh)<<16)+((cHighLow<<8)+cHighHigh);

#endif 

}

//bufer[0],bufer[1],bufer[2],bufer[4]
void CDataConvert::UInt32ToChar4(UINT32 data,unsigned char& cLowLow,unsigned char& cLowHigh,unsigned char& cHighLow,unsigned char& cHighHigh)
{
	UINT16 dataH16,dataL16;
#ifdef IS_HIGH_BEFOR 
	dataH16=data>>16;
	dataL16=data-(dataH16<<16);

	cHighHigh=dataH16>>8;
	cHighLow=dataH16-((dataH16>>8)<<8);

	cLowHigh=dataL16>>8;
	cLowLow=dataL16-((dataL16>>8)<<8);
#else
	dataH16=data>>16;
	dataL16=data-(dataH16<<16);

	cLowLow=dataH16>>8;
	cLowHigh=dataH16-((dataH16>>8)<<8);

	cHighLow=dataL16>>8;
	cHighHigh=dataL16-((dataL16>>8)<<8);
#endif 

}

//bufer[0],bufer[1]
UINT16 CDataConvert::Char2ToUInt16(unsigned char cLow,unsigned char cHigh)
{
#ifdef IS_HIGH_BEFOR 
	return  (cHigh<<8)+cLow;
#else
	return (cLow<<8)+cHigh;
#endif
}

void CDataConvert::UInt16ToChar2(UINT16 data,unsigned char&cLow,unsigned char&cHigh)
{
#ifdef IS_HIGH_BEFOR 
	cHigh=data>>8;
	cLow=data-((data>>8)<<8);
#else
	cLow=data>>8;
	cHigh=data-((data>>8)<<8);
#endif
}

